<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>SPA</title>
</head>
<body>
    <a name = 'top'></a> <!-- 锚链接 -->
    <h1>Navigation</h1>
    <ul>
        <li><a href="#home">home</a></li>
       <!--  <li><a href="#about">about</a></li>
        <li><a href="#contact">content</a></li> -->
    </ul>
    <div id="content-container" class="content">
        welcome,click on the link above to navigte
    </div>
    <div id="box" style="height:100vh;background-color: rgb(237, 147, 147);"></div>
    <a name="mid"></a>
    <a href="#top">回到顶部</a>
    <div id="box" style="height:100vh;background-color: grey;"></div>
        <a href="#mid">回到中间</a>
    <script>
        const content = document.getElementById('content-container')
         window.addEventListener('hashchange',()=>{
            
            console.log(window.location.hash)
            switch(window.location.hash){
                    case '#home':
                        content.innerHTML='<h2>Home</h2><p>welcome to the home page</p>'
                        break;
                        case '#about':
                        content.innerHTML='<h2>About</h2><p>welcome to the about page</p>'
                        break;
                        case '#contact':
                        content.innerHTML='<h2>Contact</h2><p>welcome to the contact page</p>'
                        break;
                        default:content
            }
         })
    </script>
</body>
</html>